package scanpackage.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;
import scanpackage.annotation.CustomConfig;
import scanpackage.property.RouteProperty;
import scanpackage.util.YamlUtil;

@Component
public class ConfigProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        //获取使用了我们自定义注解@CustomConfig的类
        CustomConfig configAnnotation = AnnotationUtils.findAnnotation(bean.getClass(), CustomConfig.class);
        //如果这个对象使用了此注解
        if (configAnnotation != null) {
            YamlUtil<RouteProperty> yamlUtil=new YamlUtil<>();
            return yamlUtil.getYml(RouteProperty.class,"application.yml");
        }
        return bean;
    }
}